import router from './router'
import store from '@/store'
import request from '@/util/request'
export default {
    install(Vue) {
        Vue.prototype.zhycget = async function (url, dtat) {
            let res = await request.zhycget(url, dtat)
            return res
        }
        Vue.prototype.zhycpost = async function (url, dtat) {
            let res = await request.zhycpost(url, dtat)
            return res
        }
        Vue.prototype.backs = function () {
            let jilulist = store.state.jilulist
            jilulist.map((a, b) => {
                if (a.name == store.state.routetname) {
                    jilulist.splice(b, 1);
                }
            })
            try {
                localStorage.jilulist = JSON.stringify(jilulist)
            } catch (e) {

            }
            router.back(-1)
        }
        Vue.prototype.time_p = function (t) {
            let time = new Date()
            time.setTime(t)
            let Year = time.getFullYear(),
                Month = time.getMonth() + 1,
                Data = time.getDate() < 10 ? 0 + '' + time.getDate() : time.getDate()
            Month < 10 ? Month = 0 + '' + Month : ''
            var myddy = time.getDay(); //获取存储当前日期
            console.log(myddy);
            var weekday = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
            let kjhhhs = {}
            kjhhhs.riqi = Month + "-" + Data
            kjhhhs.name = weekday[myddy]
            return kjhhhs
        }
        Vue.prototype.jindjer = function (t) {
            var myDate = new Date(); //获取今天日期
            myDate.setDate(myDate.getDate() + 7);
            var dateArray = [];
            var dateTemp;
            var flag = 1;
            var weekday = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
            for (var i = 0; i <= 7; i++) {
                let jhba = (myDate.getMonth() + 1),
                    jhbb = myDate.getDate()
                dateTemp = (jhba < 10 ? 0 + '' + jhba : jhba) + "-" + (jhbb < 10 ? 0 + '' + jhbb : jhbb);
                myDate.setDate(myDate.getDate() - flag);
                let kjhhs = {}
                kjhhs.name = weekday[myDate.getDay() + 1] || '周日'
                kjhhs.riqi = dateTemp
                dateArray.push(kjhhs);
            }
            let jjhse = dateArray.reverse()
            let jhhhsser = []
            jjhse.map((a, b) => {
                if (b == 0) {
                    a.name = '今天'
                }
                if (b == 1) {
                    a.name = '明天'
                }
                if (b <= 2) {
                    jhhhsser.push(a)
                }
            })
            return jhhhsser
        }
        Vue.prototype.time_c = function (t) {
            let time = new Date()
            time.setTime(t)
            let Year = time.getFullYear(),
                Month = time.getMonth() + 1,
                Data = time.getDate() < 10 ? 0 + '' + time.getDate() : time.getDate()
            Month < 10 ? Month = 0 + '' + Month : ''
            return Year + "-" + Month + "-" + Data
        }
        Vue.prototype.time_d = function (t) {
            let time = new Date()
            time.setTime(t)
            let Year = time.getFullYear(),
                Month = time.getMonth() + 1,
                Data = time.getDate() < 10 ? 0 + '' + time.getDate() : time.getDate(),
                hour = time.getHours() < 10 ? 0 + '' + time.getHours() : time.getHours(),
                Minutes = time.getMinutes() < 10 ? 0 + '' + time.getMinutes() : time.getMinutes(),
                Seconds = time.getSeconds() < 10 ? 0 + '' + time.getSeconds() : time.getSeconds()
            Month < 10 ? Month = 0 + '' + Month : ''
            return Year + "-" + Month + "-" + Data + " " + hour + ":" + Minutes + ":" + Seconds
        }
        Vue.prototype.hf = function (url, cu) { //路由跳转
            router.push({
                path: url,
                query: cu
            })
        }
        Vue.prototype.yanza = {
            mail: function (a) {
                var b = !1;
                return /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(a) && (b = !0), b
            },
            phone: function (a) {
                var b = !1;
                return a.match(/^13[0-9]{9}|15[0-9]{9}|14[0-9]{9}|19[0-9]{9}|16[0-9]{9}|17[0-9]{9}|18[0-9]{9}$/) && 11 == a.length && (b = !0), b
            },
            car_t: function (a) {
                var b = !1;
                return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(a) && (b = !0), b
            },
            jine: function (a) {
                var b = !1;
                return /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/.test(a) && (b = !0), b
            }

        };
    }

}
